package com.ruoyi.law.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.law.domain.entity.LawBanner;
import com.ruoyi.law.domain.entity.LawNews;
import com.ruoyi.law.domain.entity.LawService;
import com.ruoyi.law.domain.entity.LawTeam;
import com.ruoyi.law.enums.BannerLinkType;
import com.ruoyi.law.enums.ServiceType;
import com.ruoyi.law.mapper.LawBannerMapper;
import com.ruoyi.law.service.ILawBannerService;
import com.ruoyi.law.service.ILawNewsService;
import com.ruoyi.law.service.ILawServiceService;
import com.ruoyi.law.service.ILawTeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author code
 * @since 2022-12-08
 */
@Service
public class LawBannerServiceImpl extends ServiceImpl<LawBannerMapper, LawBanner> implements ILawBannerService {

    @Autowired
    private ILawServiceService serviceService;
    @Autowired
    private ILawTeamService teamService;
    @Autowired
    private ILawNewsService newsService;

    @Override
    public List<Map<String, Object>> getByType(String type) {
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> map;
        if (BannerLinkType.news.getType().equals(type)) {
            // 查询新闻
            List<LawNews> news = newsService.list();
            for (LawNews lawNews : news) {
                map = new HashMap<>(2);
                map.put("id", lawNews.getId());
                map.put("title", lawNews.getTitle());
                list.add(map);
            }
        } else if (BannerLinkType.consulting.getType().equals(type)) {
            // 查询咨询
            LambdaQueryWrapper<LawService> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(LawService::getType, ServiceType.CONSULTING.getType());
            List<LawService> serviceList = serviceService.list(queryWrapper);
            for (LawService service : serviceList) {
                map = new HashMap<>(2);
                map.put("id", service.getId());
                map.put("name", service.getTitle());
                list.add(map);
            }
        } else if (BannerLinkType.service.getType().equals(type)) {
            // 查询服务
            LambdaQueryWrapper<LawService> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(LawService::getType, ServiceType.SERVICE.getType());
            List<LawService> serviceList = serviceService.list(queryWrapper);
            for (LawService service : serviceList) {
                map = new HashMap<>(2);
                map.put("id", service.getId());
                map.put("name", service.getTitle());
                list.add(map);
            }
        } else if (BannerLinkType.lawyerInfo.getType().equals(type)) {
            // 查询律师
            List<LawTeam> teamList = teamService.list();
            for (LawTeam team : teamList) {
                map = new HashMap<>(2);
                map.put("id", team.getId());
                map.put("name", team.getName());
                list.add(map);
            }
        }
        return list;
    }
}
